package br.com.wss;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import br.com.wss.recursos.FindCursos;

public class Cursos extends Activity {
	private List<String> listCursos;
	private String busca = "";
	private String city;
	private Map<String, String> map;
	private FindCursos findCursos;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.model_list);
		Bundle bundle = getIntent().getExtras();
		if (bundle != null) {
			busca = bundle.getString("campus");
			city = bundle.getString("city");
		}

		findCursos = new FindCursos(busca);
		map = findCursos.find();
		Set<String> set = map.keySet();

		listCursos = new ArrayList<String>();
		for (String nameCurso : set) {
			listCursos.add(nameCurso);
		}
		// titulo da tela
		TextView textView = (TextView) findViewById(R.id.textViewTitle);
		textView.setText("Cursos em " + city);

		ListView view_content = (ListView) findViewById(R.id.listView_model);
		view_content.setAdapter(new ArrayAdapter<String>(this,
				R.layout.row_cursos, listCursos));

		view_content.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				String name = listCursos.get(position);
				String urlCurso = map.get(name);
				Intent i = new Intent("br.com.CURSO");
				Bundle bundle = new Bundle();
				bundle.putString("curso", urlCurso);
				bundle.putString("name", name);
				bundle.putString("url", busca);
				i.putExtras(bundle);
				startActivityForResult(i, 1);
			}

		});

	}

	public void onClickHome(View view) {
		Intent intent = new Intent(this, AppDroid.class);
		startActivity(intent);
	}

}
